package rohyunji.swing.outline;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/*스윙 기본컴퍼넌트 (레이블,버튼)
 * JLabel : 제목을 표시할때 사용
 * JButton : 클릭가능한 버튼 표시,처리를 시작하게 하는 역할 담당 버튼은 단순텍스트나 아이콘버튼,
 * 	 아이콘텍스트버튼가능.클릭시 코드 제공하려면action
 * JCheckBox :클릭가능한 확인버튼 표시 클릭할때마다 선택/비선택의 상태로 전환
 *	       단독으로 사용가능 
 *JRadioButton :클릭 가능한 확인버튼 표시 ,단독사용불가, 
 *	         그룹화해서 그중 하나만선택받음 따라서 JRadioButton들을 
 *	         ButtonGruop에 추가해둬야함
 *setTxt
 * */
public class J19_BasicComponent extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					J19_BasicComponent frame = new J19_BasicComponent();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public J19_BasicComponent() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		
		JLabel lblNewLabel = new JLabel("New label");
		panel.add(lblNewLabel);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.WEST);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
		
		final JCheckBox check1 = new JCheckBox("New check box");
		panel_1.add(check1);
		
		final JCheckBox check2 = new JCheckBox("New check box");
		panel_1.add(check2);
		
		final JCheckBox check3 = new JCheckBox("New check box");
		panel_1.add(check3);
		
		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			
				String msgs="";
				if(check1.isSelected()) msgs="1선택";
				if(check2.isSelected()) msgs+="2선택";
				if(check3.isSelected()) msgs+="3선택";
				JOptionPane.showMessageDialog(null, msgs);
					
			}
		});
		panel_1.add(btnNewButton);
		
		ButtonGroup radios=new ButtonGroup();
		
		final JRadioButton radio1 = new JRadioButton("New radio button");
		radios.add(radio1);
		final JRadioButton radio2 = new JRadioButton("New radio button");
		radios.add(radio2);
		final JRadioButton radio3 = new JRadioButton("New radio button");
		radios.add(radio3);
		JButton btn=new JButton("라디오버튼확인");
		btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String rchk="";
				if(radio1.isSelected()) rchk="1선택";
				else if(radio2.isSelected()) rchk="2선택";
				else if (radio3.isSelected()) rchk="3선택";
				JOptionPane.showMessageDialog(null, rchk);
					
			}
		});
		
		
		
		JPanel panel_3 = new JPanel();
		panel_3.setLayout(new BoxLayout(panel_3,BoxLayout.PAGE_AXIS));
		panel_3.add(radio1);
		panel_3.add(radio2);
		panel_3.add(radio3);
		panel_3.add(btn);
		
		contentPane.add(panel_3, BorderLayout.EAST);
		
		JPanel panel_4 = new JPanel();
		contentPane.add(panel_4, BorderLayout.CENTER);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.PAGE_AXIS));
		
		textField = new JTextField();
		panel_4.add(textField);
		textField.setColumns(10);
		
		passwordField = new JPasswordField();
		panel_4.add(passwordField);
		
		final JTextArea textArea = new JTextArea();
		panel_4.add(textArea);
		
		JPanel panel_2 = new JPanel();
		contentPane.add(panel_2, BorderLayout.SOUTH);
		
		JButton btnNewButton_1 = new JButton("New button");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String msg=textField.getText()+"\n"+
					new String(passwordField.getPassword())+"\n"+
						textArea.getText();
				JOptionPane.showMessageDialog(null, msg);
			}
		});
		panel_2.add(btnNewButton_1);
	}

}
